<template>
  <el-container>
    <!-- 页面顶部 -->
    <el-header>
      <div>
        <img src="../assets/懒羊羊头像.jpg" alt="" width="30px" height="auto">
        <span>xx管理系统</span>
      </div>
      <el-button type="info" @click="logout">退出</el-button>
    </el-header>
    <!-- 页面主体 -->
    <el-container id="page-body">
      <!-- 侧边栏区域 -->
      <el-aside width="200px">
        <!-- 侧边栏菜单区 -->
         <!-- 
        background-color  组件背景颜色
        text-color    文字颜色
        active-text-color    激活菜单文字颜色
         -->
         <el-menu background-color="#545c64" 
                  text-color="#ffffff"
                  active-text-color="#ffd04b" 
                  @select="handSelect"
                  router
          >
          <el-submenu v-for="item in menuList" :index="item.path" :key="item.id">
            <template slot="title">
              <i class="el-icon-location"></i>
              <span>{{item.name}}</span>
              </template>
            <!-- 渲染二级菜单 -->
            <el-menu-item v-for="item in item.children" :index="item.path" :key="item.id">
            <template slot="title">{{item.name}}</template>
            </el-menu-item>
          </el-submenu>
        </el-menu>
      </el-aside>
      <el-main>
        <router-view></router-view>
      </el-main>
    </el-container>
    <!-- <el-footer>Footer</el-footer> -->
  </el-container>
</template>
<script>
import{getMenu} from '@/api/menu'

export default {
  data() {
    return {
      menuList: []
    };
  },
  created() {
    //获取菜单
    getMenu('1').then(res => {
      this.menuList = res.data.data;
    })
  },
  methods: {
    logout() {
      // 清除token
      localStorage.removeItem('token');
      // 跳转到登录页面
      this.$router.push('/login');
    },
    handSelect(key, keyPath) {
        console.log("选择：",key, keyPath);
    }
  },
};
</script>
<style scoped>
.el-header {
  background-color: #373d41;
  color: #fff;
  display: flex;
  justify-content: space-between;
  padding-left: 50px;
  align-items: center;
  font-size: 25px;
}

div {
  display: flex;
  align-items: center;
}

span {
  margin-left: 15px;
}
.el-main {
  display: flow;
}

.el-footer {
  background-color: #b3c0d1;
  color: #333;
  text-align: center;
  line-height: 60px;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
  text-align: center;
  line-height: 200px;
}
#page-body {
  height: 650px;
}
</style>
  
  